define(function (require, exports, module) {
    'use strict';

    function ctrl($scope,$stateParams,$sce,InfoService,CommonService,$ionicLoading) {

        var par = $scope.param = new Array();

        $scope.$on('$ionicView.beforeEnter', function() {
            par.prod_code = $stateParams['prod_code'];
            init();
        });

        $scope.doRefresh = function() {
            init().finally(function(){
                $scope.$broadcast('scroll.refreshComplete');
            })
        };


        function init(){
            if(!$scope.fund){
                $ionicLoading.show();
            }
            //获取cms基金明细
            return InfoService.getOTCDetail(par.prod_code).then(function(data){
                if(data){
                    $scope.fund = data;

                    $scope.fund.sellStatus = CommonService.getOtcSellStatus($scope.fund.prod_status, $scope.fund.otc_status);

                    if($scope.fund.subscribe_desc) {
                        $scope.fund.subscribe_desc = $sce.trustAsHtml($scope.fund.subscribe_desc);
                    }
                    if($scope.fund.redeem_desc){
                        $scope.fund.redeem_desc = $sce.trustAsHtml($scope.fund.redeem_desc);
                    }
                }
                $ionicLoading.hide();
            });
        }
    }

    ctrl.$inject = ['$scope','$stateParams','$sce','InfoService','CommonService','$ionicLoading'];
    return ctrl;
});